﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Point2D
/// </summary>
public class Point2D : Tuple2D
{
	/**
    * A 2 element point that is represented by double precision floating 
    * point x,y coordinates.
    *
    */

    /**
    * Constructs and initializes a Point2d from the specified xy coordinates.
    * @param x the x coordinate
    * @param y the y coordinate
    */
    public Point2D(double x, double y) : base(x,y)
    {
        
    }

    /**
    * Constructs and initializes a Point2d from the specified Point2d.
    * @param p1 the Point2d containing the initialization x y data
    */
    public Point2D(Point2D p1) : base(p1)
    {
    }

    /**
    * Constructs and initializes a Point2d from the specified Tuple2d.
    * @param t1 the Tuple2d containing the initialization x y data
    */ 
    public Point2D(Tuple2D t1) : base(t1)
    {
    }

    /**
    * Constructs and initializes a Point2d to (0,0).
    */
    public Point2D() : base()
    {
    }

    /**
    * Computes the square of the Distance between this point and point p1.
    * @param p1 the other point
    */
    public double DistanceSquared(Point2D p1)
    {
	    double dx, dy;

	    dx = this.x-p1.x;  
	    dy = this.y-p1.y;
	    return dx*dx+dy*dy;
    }

    /**
    * Computes the Distance between this point and point p1.
    * @param p1 the other point 
    */    
    public double Distance(Point2D p1)
    {
	    double  dx, dy;

	    dx = this.x-p1.x;  
	    dy = this.y-p1.y;
	    return Math.Sqrt(dx*dx+dy*dy);
    }


    /**
    * Computes the L-1 (Manhattan) Distance between this point and
    * point p1.  The L-1 Distance is equal to abs(x1-x2) + abs(y1-y2).
    * @param p1 the other point
    */
    public double DistanceL1(Point2D p1)
    {
	    return (Math.Abs(this.x-p1.x) + Math.Abs(this.y-p1.y));
    }

    /**
    * Computes the L-infinite Distance between this point and
    * point p1.  The L-infinite Distance is equal to 
    * MAX[abs(x1-x2), abs(y1-y2)]. 
    * @param p1 the other point
    */
    public double DistanceLinf(Point2D p1)
    {
	    return Math.Max(Math.Abs(this.x-p1.x), Math.Abs(this.y-p1.y));
    }
}
